home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / PowerPlant / Everything / CModalStuff.cp < prev    next >
Encoding:
Text File  |  1998-10-11  |  7.0 KB  |  320 lines  |  [TEXT/CWIE]

  1. // CModalStuff.cp -- dialog methods
  2.  
  3. #include "CModalStuff.h"
  4.  
  5. #include <UEnvironment.h>
  6. #include <UReanimator.h>
  7. #include <URegistrar.h>
  8. #include <LStream.h>
  9. #include <LTabGroup.h>
  10. #include <LPushButton.h>
  11. #include <LAMPushButtonImp.h>
  12. #include <LGAPushButtonImp.h>
  13. #include <CustomControls.h>
  14. #include <LTextGroupBox.h>
  15. #include <LAMControlViewImp.h>
  16. #include <LGATextGroupBoxImp.h>
  17. #include <LPopupButton.h>
  18. #include <LAMPopupButtonImp.h>
  19. #include <LGAPopupButtonImp.h>
  20. #include <LScrollerView.h>
  21. #include <LScrollBar.h>
  22. #include <LAMTrackActionImp.h>
  23. #include <LStdScrollBarImp.h>
  24. #include <LTextTableView.h>
  25. #include <LCellSizeToFit.h>
  26. #include <LTextArray.h>
  27. #include <LTableArrayStorage.h>
  28. #include <UAttachments.h>
  29. #include <LTableMonoGeometry.h>
  30. #include <LTableSingleSelector.h>
  31. #include <CTextUtils.h>
  32.  
  33. #include "DModalStuffData.h"
  34. #include "EverythingCmds.h"
  35. #include <PP_Messages.h>
  36.  
  37. const MessageT    msgTools    = 'Toos';
  38. const MessageT    msgFromValuesList2    = 'Fro2';
  39. const MessageT    msgFromMenu    = 'Frou';
  40. const MessageT    msgTextList    = 'Text';
  41.  
  42. #define PPob_ModalStuffID    212
  43. #define RidL_ModalStuffID    212
  44.  
  45. Boolean        CModalStuff::sIsRegistered = false;
  46.  
  47. //----------
  48. CModalStuff*        CModalStuff::CreateModalStuff (
  49.     LCommander*        inSuperCommander,
  50.     CommandT        inCommand,
  51.     DModalStuffData*        inData)
  52. {
  53.     if (!sIsRegistered) {
  54.         RegisterClass ();
  55.     }
  56.     CModalStuff*        dlog;
  57.     dlog = ((CModalStuff *)LWindow::CreateWindow(PPob_ModalStuffID, inSuperCommander));
  58.     dlog->mCommand = inCommand;
  59.     dlog->SetFromData (inData);
  60.  
  61.     return dlog;
  62. }
  63.  
  64. //----------
  65. #define    RegisterClasses(AbstractClass,AMImpClass,GAImpClass)    \
  66.     RegisterClass_(AbstractClass);    \
  67.     if (useAppearance) {    \
  68.         RegisterClassID_(AMImpClass, AbstractClass::imp_class_ID);    \
  69.     } else {    \
  70.         RegisterClassID_(GAImpClass, AbstractClass::imp_class_ID);    \
  71.     }
  72.  
  73. //----------
  74. void    CModalStuff::RegisterClass ()
  75. {
  76.     Boolean        useAppearance = UEnvironment::HasFeature (env_HasAppearance);
  77.  
  78.     RegisterClass_(CModalStuff);
  79.  
  80.     // register the pane classes we use
  81.     RegisterClasses (LPushButton, LAMPushButtonImp, LGAPushButtonImp);
  82.     RegisterClasses (CControlPane, CustomControlImp, CustomControlImp);
  83.     RegisterClasses (LTextGroupBox, LAMControlViewImp, LGATextGroupBoxImp);
  84.     RegisterClasses (LPopupButton, LAMPopupButtonImp, LGAPopupButtonImp);
  85.     RegisterClass_(LScrollerView);
  86.     RegisterClasses (LScrollBar, LAMTrackActionImp, LStdScrollBarImp);
  87.     RegisterClass_(LTextTableView);
  88.  
  89.     sIsRegistered = true;
  90. }
  91.  
  92. //----------
  93. CModalStuff::CModalStuff (
  94.     LStream*    inStream)
  95.     : LGADialog (inStream)
  96. {
  97.     mData = nil;
  98. }
  99.  
  100. //----------
  101. CModalStuff::~CModalStuff()
  102. {
  103.     delete mData;
  104. }
  105.  
  106. //----------
  107. //    This member function gets called once the containment hierarchy that contains
  108. //    this pane has been built. It gives us a chance to get data members for
  109. //    interesting subviews, and to do other operations now that our subviews exist.
  110. void    CModalStuff::FinishCreateSelf()
  111. {
  112.     LGADialog::FinishCreateSelf();
  113.  
  114.     mOKButton = (LPushButton*) FindPaneByID ('OK  ');
  115.  
  116.     mToolsPalette = (CControlPane*) FindPaneByID ('Toos');
  117.  
  118.     mFromValuesList2Popup = (LPopupButton*) FindPaneByID ('Fro2');
  119.  
  120.     mFromMenuPopup = (LPopupButton*) FindPaneByID ('Frou');
  121.  
  122.     mTextListTable = (LTextTableView*)FindPaneByID ('Text');
  123.     mTextListTable->AddListener(this);  // not a control so can't be included in RidL
  124.     mTextListTable->SetCellSizer (new LCellSizeToFit ());
  125.     mTextListTable->AddAttachment(new LEraseAttachment());
  126.     mTextListTable->SetTableGeometry(new LTableMonoGeometry(mTextListTable, 
  127.                             68 /* col width */, 
  128.                             11  /* row height */));
  129.     mTextListTable->SetTableSelector(new LTableSingleSelector(mTextListTable));
  130. // use LTextArray to contain list items
  131.     LTextArray* mTextListTableArray = new LTextArray;
  132.     *mTextListTableArray += "One";
  133.     *mTextListTableArray += "Two";
  134.     *mTextListTableArray += "Three";
  135.     *mTextListTableArray += "Infinity";
  136.     mTextListTable->SetTableStorage(new LTableArrayStorage(mTextListTable, mTextListTableArray));
  137.  
  138.  
  139.     UReanimator::LinkListenerToControls(this, this, RidL_ModalStuffID);
  140.         // the purpose is to "connect" self to whatever controls
  141.         // that we want to "listen" to
  142.  
  143. // any additional initialization for your dialog:
  144.  
  145. }
  146.  
  147. //----------
  148. void    CModalStuff::SetFromData (
  149.     DModalStuffData*        inData)
  150. {
  151.     mData = inData;
  152.     mData->AddListener (this);
  153.  
  154.     mToolsPalette->SetValue (mData->GetTools2 ());
  155.     mFromValuesList2Popup->SetValue (mData->GetFromValuesList3 ());
  156.     mFromMenuPopup->SetValue (mData->GetFromMenu2 ());
  157.     mTextListTable->SetValue (mData->GetTextList2 ());
  158. }
  159.  
  160. //----------
  161. DModalStuffData*        CModalStuff::GetData ()
  162. {
  163.  
  164.     return mData;
  165. }
  166.  
  167. //----------
  168. void    CModalStuff::DataChanged (
  169.     long        inDataID)
  170. {
  171.     StopListening ();
  172.  
  173.     if (inDataID == idTools2) {
  174.         mToolsPalette->SetValue (mData->GetTools2 ());
  175.     }
  176.     if (inDataID == idFromValuesList3) {
  177.         mFromValuesList2Popup->SetValue (mData->GetFromValuesList3 ());
  178.     }
  179.     if (inDataID == idFromMenu2) {
  180.         mFromMenuPopup->SetValue (mData->GetFromMenu2 ());
  181.     }
  182.     if (inDataID == idTextList2) {
  183.         mTextListTable->SetValue (mData->GetTextList2 ());
  184.     }
  185.  
  186.     StartListening ();
  187. }
  188.  
  189. //----------
  190. void    CModalStuff::ListenToMessage (
  191.     MessageT    inMessage,
  192.     void        *ioParam)
  193. {
  194.     switch (inMessage) {
  195.     case msg_OK:
  196.             GetSuperCommander()->ProcessCommand(-mCommand, this);
  197.         break;
  198.  
  199.     case msg_Cancel:
  200.             DoClose();
  201.         break;
  202.  
  203.     case msgDataChanged:
  204.             DataChanged ((long)ioParam);
  205.         break;
  206.  
  207.     case msgTools:
  208.             mData->SetTools2 (mToolsPalette->GetValue ());
  209.         break;
  210.  
  211.     case msgFromValuesList2:
  212.             mData->SetFromValuesList3 (mFromValuesList2Popup->GetValue ());
  213.         break;
  214.  
  215.     case msgFromMenu:
  216.             mData->SetFromMenu2 (mFromMenuPopup->GetValue ());
  217.         break;
  218.  
  219.     case msgTextList:
  220.             mData->SetTextList2 (mTextListTable->GetValue ());
  221.         break;
  222.  
  223.  
  224.     default:
  225.           ; // do something
  226.         break;
  227.     }
  228. }
  229.  
  230. //----------
  231. Boolean        CModalStuff::ObeyCommand (
  232.     CommandT    inCommand,
  233.     void*        ioParam)
  234. {
  235.     Boolean        cmdHandled = true;
  236.  
  237.     if (inCommand < 0) {
  238.         // modal dialog has finished
  239.  
  240.         switch (-inCommand) {
  241.         }
  242.  
  243.     } else {
  244.         switch (inCommand) {
  245.  
  246.         default:
  247.                 cmdHandled = LGADialog::ObeyCommand(inCommand, ioParam);
  248.             break;
  249.         }
  250.     }
  251.  
  252.     return cmdHandled;
  253. }
  254.  
  255. //----------
  256. void    CModalStuff::FindCommandStatus (
  257.     CommandT    inCommand,
  258.     Boolean        &outEnabled,
  259.     Boolean        &outUsesMark,
  260.     Char16        &outMark,
  261.     Str255        outName)
  262. {
  263.     outUsesMark = false;
  264.  
  265.     switch (inCommand) {
  266.  
  267.     // +++ Add cases here for the commands you handle
  268.  
  269.     default:
  270.             LGADialog::FindCommandStatus(inCommand, outEnabled,
  271.                                             outUsesMark, outMark, outName);
  272.         break;
  273.     }
  274. }
  275.  
  276. // following functions will be obsoleted
  277. // retained only for backwards compatibility
  278. //----------
  279. Boolean
  280. CModalStuff::GetToolsChoice()
  281. {
  282.     return mToolsPalette->GetValue();
  283. }
  284.  
  285. void
  286. CModalStuff::SetToolsChoice (
  287.     Int32        inChoice)
  288. {
  289.     mToolsPalette->SetValue (inChoice);
  290. }
  291.  
  292. //----------
  293. short
  294. CModalStuff::GetFromValuesList2PopupChoice ()
  295. {
  296.     return mFromValuesList2Popup->GetValue();
  297. }
  298.  
  299. void
  300. CModalStuff::SetFromValuesList2PopupChoice (
  301.     short        choice)
  302. {
  303.     mFromValuesList2Popup->SetValue (choice);
  304. }
  305.  
  306. //----------
  307. short
  308. CModalStuff::GetFromMenuPopupChoice ()
  309. {
  310.     return mFromMenuPopup->GetValue();
  311. }
  312.  
  313. void
  314. CModalStuff::SetFromMenuPopupChoice (
  315.     short        choice)
  316. {
  317.     mFromMenuPopup->SetValue (choice);
  318. }
  319.  
  320.